import 'package:get/get.dart';
import 'package:tiktokadult/alert_business/video/video_buy_bottom_sheet.dart';
import 'package:tiktokadult/alert_business/video/vip_acg_dailog.dart';
import 'package:tiktokadult/hj_model/video_model.dart';
import 'package:tiktokadult/hj_page/community_business/post_detail_page/community_image_page.dart';
import 'package:tiktokadult/hj_utils/api_service/vid_service.dart';
import 'package:tiktokadult/hj_utils/global.dart';
import 'package:tiktokadult/hj_utils/history_record_util.dart';

//图集详情页
class PicsDetailLogic extends GetxController {
  final String? id;
  VideoModel? videoModel;
  RxBool galleryMode = false.obs; //画廊模式

  PicsDetailLogic(this.id);

  onReady() {
    super.onReady();
    loadData();
  }

  Future loadData() async {
    videoModel = await VidService.getVideoDetail(id ?? "");
    if (videoModel != null) {
      HistoryRecordUtil.insertHistoryModel<VideoModel>(videoModel!, HistoryRecordType.picture);
    }
    videoModel ??= VideoModel();
    update();
  }

  onImgItemClick(int index) async {
    if (videoModel?.picLockType == 0) {
      Get.to(CommunityImagePage(
        videoModel: videoModel,
        index: index,
        showDownLoad: true,
      ));
    } else if (videoModel?.picLockType == 1) {
      final res = await Get.bottomSheet(VideoBuyBottomSheet(videoM: videoModel!));
      if (res == true) {
        videoModel?.vidStatus?.hasPaid = true;
        showToast('购买成功～');
        update();
      }
    } else if (videoModel?.picLockType == 2) {
      await Get.dialog(VipACGDialog());
    }
  }

  changeGalleryMode() {
    galleryMode.value = !galleryMode.value;
    update();
  }
}
